trigger WFTRigger on Workflow_Definition__c (after Update) {
    list<Workflow_Definition__c> WFList = new list<Workflow_Definition__c>();
    Map<string,id> WFnewVersion = new map<string,id>();    
    list<Workflow_Fulfillment_Group__c> grpList = new list<Workflow_Fulfillment_Group__c>();  
    list<Workflow_Fulfillment_Group__c> WFGroups = new list<Workflow_Fulfillment_Group__c>();    
    
   for(Workflow_Definition__c WF : trigger.new){
        if(WF.status__c != trigger.oldMap.get(WF.id).status__c && WF.status__c =='Active' && WF.derived_from__c != null)
        WFnewVersion.put(WF.derived_from__c, WF.id); 
    }
    for(Workflow_Fulfillment_Group__c grpToUpdate: [select Workflow__c from Workflow_Fulfillment_Group__c where Workflow__c in :WFnewVersion.keySet()]){
        grpToUpdate.Workflow__c = WFnewVersion.get(grpToUpdate.Workflow__c);
        grpList.add(grpToUpdate); 
    }
    
    try{Update grpList;}
    Catch(dmlException e){GeneralConstants.mailAnyExceptionToMe('WFTRigger ', 'Trigger' , e);}    
}